home *** CD-ROM | disk | FTP | other *** search
- /* ftell.c, from p. 437 of Turbo C Bible */
- #include <stdio.h>
- main()
- {
- long curpos;
- FILE *infile;
- char filename[80], buffer[80];
- printf("Enter name of a text file: ");
- gets(filename);
- /* Open the file for reading */
- if ((infile = fopen(filename, "rb")) == NULL)
- {
- printf("fopen failed.");
- exit(0);
- }
- /* Read 80 character and display the */
- /* buffer */
- fread(buffer, sizeof(char), 80, infile);
- printf("read these 80 characters:\n %s\n", buffer);
- /* Get and display current position */
- if ((curpos = ftell(infile)) == -1L)
- {
- perror("ftell failed!");
- }
- else
- {
- printf("Currently at %ld bytes from beginning \
- of file\n", curpos);
- }
- }